<template>
  <div ref="container">
    <a-form @submit="handleSubmit" :form="form" :bordered="false">
      <a-modal width="80%" :visible="visible" :confirmLoading="confirmLoading" @cancel="handleCancel" style="padding:0px;">
        <template slot="footer">
          <a-button key="cancel" class="common-btn" @click="handleCancel">取消</a-button>
          <a-button key="submit" class="common-btn" @click="handleSubmit">确定</a-button>
        </template>
        <a-card :bordered="false" class="card-common">
          <a-row clss="form-row" :gutter="16">
            <a-col :lg="8" :md="12" :sm="24">
              <a-form-item label="项目编号" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
                <a-input v-model="queryParam.proCode" placeholder="项目编号"/>
              </a-form-item>
            </a-col>
            <a-col :lg="8" :md="12" :sm="24">
              <a-form-item label="项目名称" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
                <a-textarea v-model="queryParam.proName" rows="1" placeholder="项目名称"/>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row clss="form-row" :gutter="16">
            <a-col :lg="8" :md="12" :sm="24">
              <a-form-item label="责任单位" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
                <a-input v-model="queryParam.dutyCompany" placeholder="项目编号"/>
              </a-form-item>
            </a-col>
            <a-col :lg="8" :md="12" :sm="24">
              <a-form-item label="改造路径" :labelCol="{lg: {span: 8}, sm: {span: 7}}" :wrapperCol="{lg: {span: 14}, sm: {span: 17} }">
                <a-textarea v-model="queryParam.proType" rows="1" placeholder="项目名称"/>
              </a-form-item>
            </a-col>
            <a-col :lg="2" :md="12" :sm="24">
              <a-form-item label="" :colon="false">
                <a-button class="common-btn" @click="toSearch('2')" style="margin-top: 8px;">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
          <a-table
            :columns="columns"
            :rowSelection="{onChange: onSelectChange}"
            :dataSource="loadData"
            bordered
            :loading="loading"
            :pagination="false"
            :scroll="{ x: 1350 }">
          </a-table>
        </a-card>
      </a-modal>
    </a-form>
  </div>
</template>

<script>
import Breadcrumb from '@/components/tools/Breadcrumb'
// import { getSupplierList } from '@/api/mockdata'
export default {
  name: 'ProEndingModel',
  components: {
    Breadcrumb
  },
  data () {
    return {
      name: '',
      breadList: [],
      selectedRowKeys: [],
      visible: false,
      confirmLoading: false,
      loading: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '项目编号',
          width: '6%',
          dataIndex: 'proCode'
        }, {
          title: '项目名称',
          width: '8%',
          dataIndex: 'proName'
        }, {
          title: '责任单位',
          width: '8%',
          dataIndex: 'dutyCompany'
        }, {
          title: '联系人',
          width: '6%',
          dataIndex: 'proPerson'
        }, {
          title: '联系电话',
          width: '8%',
          dataIndex: 'proTel'
        },
        {
          title: '总用户数',
          width: '6%',
          dataIndex: 'totalCount'
        },
        {
          title: '总建筑面积',
          width: '8%',
          dataIndex: 'totalEara'
        },
        {
          title: '改造路径',
          width: '8%',
          dataIndex: 'proType'
        },
        {
          title: '开工时间',
          width: '10%',
          dataIndex: 'proStart'
        },
        {
          title: '完工时间',
          width: '10%',
          dataIndex: 'proEnd'
        },
        {
          title: '项目完工进度',
          width: '6%',
          dataIndex: 'proPlan'
        },
        {
          title: '结项发起时间',
          width: '10%',
          dataIndex: 'updateEndTime'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: []
    }
  },
  created () {
    this.loading = true
    this.selectedRowKeys = []
    this.getBreadCrumb()
    setTimeout(() => {
      this.getData('1')
    }, 1000)
  },
  methods: {
    // 面包屑处理
    getBreadCrumb () {
      this.breadList = []
      this.name = this.$route.name
      this.$route.matched.forEach(item => {
        console.log('1111', item)
        this.breadList.push(item)
      })
    },
    add () {
      this.visible = true
      this.$emit('add')
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRows
    },
    getData (code) {
      const data = [
        {
          proCode: 'SX_TY_001',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }, {
          proCode: 'SX_TY_002',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }, {
          proCode: 'SX_TY_003',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }, {
          proCode: 'SX_TY_004',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }, {
          proCode: 'SX_TY_005',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }, {
          proCode: 'SX_TY_006',
          proName: '世界500强',
          dutyCompany: '大中国',
          proPerson: '王老五',
          proTel: '18899999999',
          totalCount: '999999999',
          totalEara: '100000',
          proType: '煤改电',
          proStart: '2015-12-30',
          proEnd: '2019-01-01',
          proPlan: '100%',
          updateEndTime: '2020-02-02'
        }
      ]
      if (code === '1') {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
        }, 1000)
      } else {
        this.loadData = data
        setTimeout(() => {
          this.loading = false
          this.$success({
            title: '查询成功'
          })
        }, 1000)
      }
    },
    toSearch (status) {
      this.loading = true
      this.getData(status)
    },
    handleSubmit () {
      const that = this
      this.$confirm({
        title: '确认当前项目可以结项吗',
        okText: '确认',
        cancelText: '取消',
        onOk () {
          that.$success({
            title: '当前项目已处理为结项'
          })
          that.visible = false
        }
      })
    },
    handleCancel () {
      this.visible = false
    }
  }
}

</script>

<style lang="less" scoped>
.card-common {
  margin-bottom: 0px;
}
/deep/.ant-card-body {
  padding: 24px 24px 0;
}
</style>
